package net.wnb.mineclearance.ui;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;

import javax.swing.JButton;
import javax.swing.JEditorPane;
import javax.swing.JPanel;

import wnb.util.io.Terminal;

public class AboutPane extends JPanel implements ActionListener {
	public static final String ABOUT_FILE_NAME = "res/about.html";

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private static final int DEFAULT_WIDTH = 320;
	private static final int DEFAULT_HEIGHT = 480;
	
	private JEditorPane editorPane;
	private JButton btnBack;

	public AboutPane(){
		init();
		
		setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
		setLayout(new BorderLayout());
		add(editorPane, BorderLayout.CENTER);
		add(btnBack, BorderLayout.SOUTH);
		validate();
	}
	
	private void init(){
		try {
			File file = new File(ABOUT_FILE_NAME);
			editorPane = new JEditorPane(file.toURI().toURL());
			editorPane.setEditable(false);
		} catch (IOException e) {
			Terminal.write(e.getMessage());
			e.printStackTrace();
		}
		
		btnBack = new JButton("返回");
		btnBack.setPreferredSize(new Dimension(getWidth(), 32));
		btnBack.addActionListener(this);
	}

	@Override
	public void actionPerformed(ActionEvent event) {
		Object source = event.getSource();
		if(source.equals(btnBack)){
			MenuPane pane = new MenuPane();
			MainWindow win = MainWindow.getInstance();
			win.setPane(pane);
			win.validate();
		}
	}
}
